/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.homullus;

import java.util.ArrayList;
import org.lwjgl.opengl.GL11;
/**
 *
 * @author Gary
 */
public class Shape
{
    private ArrayList<Quad> quads = new ArrayList<Quad>();
    private ArrayList<Triangle> triangles = new ArrayList<Triangle>();

    private boolean wireframe = false;
    public void SetWireframe(boolean b) {  wireframe = b; }
    public boolean IsWireframe() { return wireframe; }


    public void AddQuad(Quad q)
    {
        quads.add(q);
    }

    public void AddTriangle(Triangle t)
    {
        triangles.add(t);
    }

    public void Draw()
    {
        if (quads.size() > 0)
        {
            if (IsWireframe())
            {
                GL11.glBegin(GL11.GL_LINES);
                for(int q = 0; q < quads.size(); q++)
                {
                    GL11.glVertex3f(quads.get(q).getFirstPoint().x, quads.get(q).getFirstPoint().y, quads.get(q).getFirstPoint().z);
                    GL11.glVertex3f(quads.get(q).getSecondPoint().x, quads.get(q).getSecondPoint().y, quads.get(q).getSecondPoint().z);

                    GL11.glVertex3f(quads.get(q).getSecondPoint().x, quads.get(q).getSecondPoint().y, quads.get(q).getSecondPoint().z);
                    GL11.glVertex3f(quads.get(q).getThirdPoint().x, quads.get(q).getThirdPoint().y, quads.get(q).getThirdPoint().z);

                    GL11.glVertex3f(quads.get(q).getThirdPoint().x, quads.get(q).getThirdPoint().y, quads.get(q).getThirdPoint().z);
                    GL11.glVertex3f(quads.get(q).getFourthPoint().x, quads.get(q).getFourthPoint().y, quads.get(q).getFourthPoint().z);

                    GL11.glVertex3f(quads.get(q).getFourthPoint().x, quads.get(q).getFourthPoint().y, quads.get(q).getFourthPoint().z);
                    GL11.glVertex3f(quads.get(q).getFirstPoint().x, quads.get(q).getFirstPoint().y, quads.get(q).getFirstPoint().z);

                }
                GL11.glEnd();
            }
            else
            {
                GL11.glBegin(GL11.GL_QUADS);
                for(int q = 0; q < quads.size(); q++)
                {
                    GL11.glVertex3f(quads.get(q).getFirstPoint().x, quads.get(q).getFirstPoint().y, quads.get(q).getFirstPoint().z);
                    GL11.glVertex3f(quads.get(q).getSecondPoint().x, quads.get(q).getSecondPoint().y, quads.get(q).getSecondPoint().z);
                    GL11.glVertex3f(quads.get(q).getThirdPoint().x, quads.get(q).getThirdPoint().y, quads.get(q).getThirdPoint().z);
                    GL11.glVertex3f(quads.get(q).getFourthPoint().x, quads.get(q).getFourthPoint().y, quads.get(q).getFourthPoint().z);
                }
                GL11.glEnd();
            }
        }
        if (triangles.size() > 0)
        {
            if (IsWireframe())
            {
                GL11.glBegin(GL11.GL_LINES);
                for(int t = 0; t < triangles.size(); t++)
                {
                    GL11.glVertex3f(triangles.get(t).getFirstPoint().x, triangles.get(t).getFirstPoint().y, triangles.get(t).getFirstPoint().z);
                    GL11.glVertex3f(triangles.get(t).getSecondPoint().x, triangles.get(t).getSecondPoint().y, triangles.get(t).getSecondPoint().z);

                    GL11.glVertex3f(triangles.get(t).getSecondPoint().x, triangles.get(t).getSecondPoint().y, triangles.get(t).getSecondPoint().z);
                    GL11.glVertex3f(triangles.get(t).getThirdPoint().x, triangles.get(t).getThirdPoint().y, triangles.get(t).getThirdPoint().z);

                    GL11.glVertex3f(triangles.get(t).getThirdPoint().x, triangles.get(t).getThirdPoint().y, triangles.get(t).getThirdPoint().z);
                    GL11.glVertex3f(triangles.get(t).getFirstPoint().x, triangles.get(t).getFirstPoint().y, triangles.get(t).getFirstPoint().z);
                }
                GL11.glEnd();
            }
            else
            {
                GL11.glBegin(GL11.GL_TRIANGLES);
                for(int t = 0; t < triangles.size(); t++)
                {
                    GL11.glVertex3f(triangles.get(t).getFirstPoint().x, triangles.get(t).getFirstPoint().y, triangles.get(t).getFirstPoint().z);
                    GL11.glVertex3f(triangles.get(t).getSecondPoint().x, triangles.get(t).getSecondPoint().y, triangles.get(t).getSecondPoint().z);
                    GL11.glVertex3f(triangles.get(t).getThirdPoint().x, triangles.get(t).getThirdPoint().y, triangles.get(t).getThirdPoint().z);
                }
                GL11.glEnd();
            }
        }
    }
}
